package com.xuzimian.globaldemo.spring.springrpc.webservice;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.remoting.jaxws.JaxWsPortProxyFactoryBean;
import org.springframework.remoting.jaxws.SimpleJaxWsServiceExporter;

import java.net.MalformedURLException;
import java.net.URL;

/**
 * @program: global-demo
 * @description:
 * @author: xzm
 * @create: 2019-01-16 16:46
 **/
//@Configuration
public class WebServiceConfig {

    /**
     * 导出并发布一个webservice
     * @return
     */
    @Bean
    public SimpleJaxWsServiceExporter jaxWsServiceExporter() {
        /**
         * return new SimpleJaxWsServiceExporter();
         * 因为@WebService(serviceName = "SpringWebService") 使用了serviceName，
         * 所以，使用上面返回的默认SimpleJaxWsServiceExporter导出器，将形成web服务
         * 地址为： http://localhost:8080/SpringWebService。
         * 而如下设置将形成地址：http://localhost:8080/services/SpringWebService
         */
        SimpleJaxWsServiceExporter exporter = new SimpleJaxWsServiceExporter();
        exporter.setBaseAddress("http://localhost:8080/services/");

        return exporter;
    }

    @Bean
    public JaxWsPortProxyFactoryBean clientSpringWebService() throws MalformedURLException {
        JaxWsPortProxyFactoryBean proxy=new JaxWsPortProxyFactoryBean();
        proxy.setWsdlDocumentUrl(new URL("http://localhost:8080/services/SpringWebService"));
        proxy.setServiceInterface(SpringWebService.class);
        proxy.setServiceName("SpringWebService");
        proxy.setPortName("HelloServiceImplPort");
        proxy.setNamespaceUri("http://www.xuzmian.com");
        return proxy;
    }
}
